{extend name="index_layout"/}
{block name="main"}
<link href="/static/libs/formSelects-v4.css" rel="stylesheet" />
<script src="/static/libs/formSelects-v4.js"></script>
<form class="layui-form" method="post" id="pform">
    <!-- 用户信息 -->
    <input type="hidden" name="mobile" value="{$admin.mobile}">
    <input type="hidden" name="nickname" value="{$admin.nickname}">
    <input type="hidden" name="username" value="{$admin.username}">
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="bitian">*</span>产品编号 </label>
        <div class="layui-input-block">
            <input type="text" name="nums" lay-verify="required" autocomplete="off" placeholder="产品编号" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="bitian">*</span>产品名称 </label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="产品名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="bitian">*</span>库存单位 </label>
        <div class="layui-input-block">
            <select name="danwei_id" id="danwei_id" lay-filter="changeValue">
                {volist name="danwei" id="item"}
                <option value="{$item.id}">{$item.title}</option>
                {/volist}
            </select>
            <input type="hidden" name="danwei" value="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">产品规格 </label>
        <div class="layui-input-block">
            <input type="text" name="guige" autocomplete="off" placeholder="产品规格" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">库存数量 </label>
        <div class="layui-input-block">
            <span style="line-height: 36px;">0</span>
        </div>
    </div>
    {volist name="custom" id="item" key="k"}
        {switch item.field_type}
            {case text}
                <div class="layui-form-item" id="extra_{$k}">
                    <label class="layui-form-label">{if strpos($item.attribute.attribute,'2') !== false} <span class="bitian">*</span>{/if} {$item.title} </label>
                    <div class="layui-input-block">
                        <input type="hidden" name="extra-title[]" value="{$item.title}">
                        <input type="hidden" name="field_type[]" value="{$item.field_type}">
                        <input type="text" name="extra_{$k}" {if strpos($item.attribute.attribute,'2') !== false} lay-verify="required" {/if} autocomplete="off" placeholder="{$item.attribute.placeholder}" class="layui-input {if strpos($item.attribute.attribute,'1') !== false} layui-disabled {/if}">
                    </div>
                </div>
            {/case}
            {case number}
                <div class="layui-form-item" id="extra_{$k}">
                    <label class="layui-form-label">{if strpos($item.attribute.attribute,'2') !== false} <span class="bitian">*</span>{/if} {$item.title} </label>
                    <div class="layui-input-block">
                        <input type="hidden" name="extra-title[]" value="{$item.title}">
                        <input type="hidden" name="field_type[]" value="{$item.field_type}">
                        <input type="text" name="extra_{$k}" {if strpos($item.attribute.attribute,'2') !== false} lay-verify="required" {/if} autocomplete="off" placeholder="{$item.attribute.placeholder}" class="layui-input {if strpos($item.attribute.attribute,'1') !== false} layui-disabled {/if}" {if strpos($item.attribute.attribute,'4') !== false} onclick="saveXiaoshu(this,'{$item.attribute.xiaoshu}')"{/if} {if strpos($item.attribute.attribute,'3') !== false} qian="1" onkeyup="SnumFormat(this)" {/if} >
                    </div>
                </div>
            {/case}
            {case time}
                <div class="layui-form-item" id="extra_{$k}">
                    <label class="layui-form-label">{if strpos($item.attribute.attribute,'2') !== false} <span class="bitian">*</span>{/if} {$item.title} </label>
                    <div class="layui-input-block">
                        <input type="hidden" name="extra-title[]" value="{$item.title}">
                        <input type="hidden" name="field_type[]" value="{$item.field_type}">
                        <input type="text" name="extra_{$k}" id="test1" class="layui-input">
                    </div>
                </div>
            {/case}
            {case radio}
                <div class="layui-form-item" id="extra_{$k}">
                    <label class="layui-form-label">{if strpos($item.attribute.attribute,'1') !== false} <span class="bitian">*</span>{/if} {$item.title} </label>
                    <div class="layui-input-block">
                        <input type="hidden" name="extra-title[]" value="{$item.title}">
                        <input type="hidden" name="field_type[]" value="{$item.field_type}">
                        <select name="extra_{$k}" id="" lay-filter="changeValue">
                            <option value="0">请选择</option>
                            {volist name="item.attribute.select" id="select"}
                            <option value="{$select}">{$select}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
            {/case}
            {case checkbox}
                <div class="layui-form-item" id="extra_{$k}">
                    <label class="layui-form-label">{if strpos($item.attribute.attribute,'1') !== false} <span class="bitian">*</span>{/if} {$item.title} </label>
                    <div class="layui-input-block">
                        <input type="hidden" name="extra-title[]" value="{$item.title}">
                        <input type="hidden" name="field_type[]" value="{$item.field_type}">
                        <select name="extra_{$k}" id="" class="mutiple-select" xm-select-search=""  xm-select="userDetailOrganizationSelectId{$k}" lay-filter="changeValue">
                            {volist name="item.attribute.select" id="select"}
                            <option value="{$select}">{$select}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
            {/case}
        {/switch}
    {/volist}

    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter='ds' type="button" data-refresh="false">立即提交</button>
            <button class="layui-btn layui-btn-normal" type="button" onclick="var index1 = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index1);">返回</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script src="/static/libs/laydate/laydate.js"></script>
<script>
    $(function(){
        $('input[name="danwei"]').val($('#danwei_id option:selected').text());
        $('.mutiple-select').each(function(){
            var xm_select_id = $(this).attr('xm-select');
            layui.formSelects.render(xm_select_id, {
                skin: "normal", //多选皮肤normal|primary|default|danger|warm
                height: "auto",                //是否固定高度, 38px | auto
                radio: false,                  //是否设置为单选模式
                direction: "down",        //显示方式向下显示
                on: function(id, vals, val, isAdd, isDisabled){
                    hideForm()
                },            //同formSelects.on
            })
        })
    })
    layui.use(['form','jquery','laydate'], function() {
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        form.on('submit(ds)',function(data){
            var param = data.field;
            $.post('{:url("editPost")}',param,function(res){
                if(res.code > 0){
                    layer.msg('添加成功');
                    setTimeout(() => {
                        var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index1);
                        parent.location.reload();
                    }, 500);
                }else{
                    layer.msg(res.msg);
                }
            },'json');
        })
        laydate.render({
            elem: '#test1', //指定元素
            type:"datetime",
            change:function(value,date,endDate){
                hideForm()
            }
        });
        
        $('input').on('change',function(){
            hideForm()
        })
        form.on('select(changeValue)',function(){
            $('input[name="danwei"]').val($('#danwei_id option:selected').text());
            hideForm();
        })
        
    })

    var custom = JSON.parse('{:json_encode($custom)}');
    hiddenList = [];
    for(var i in custom){
        hidden = custom[i].attribute.hidden;
        if(hidden){
            hiddenList.push({'key':i,'hidden':hidden});
        }
    }
</script>
<script src="/static/libs/hide.js"></script>
{/block}